package com.lagou.redis_demo;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
import java.util.Set;

public class TestRedis {

    public static void main(String[] args) {

        Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
        //Jedis Cluster will attempt to discover cluster nodes automatically
        jedisClusterNodes.add(new HostAndPort("192.168.80.4", 7000));
        jedisClusterNodes.add(new HostAndPort("192.168.80.4", 7001));
        jedisClusterNodes.add(new HostAndPort("192.168.80.4", 7002));
        jedisClusterNodes.add(new HostAndPort("192.168.80.4", 7003));
        jedisClusterNodes.add(new HostAndPort("192.168.80.4", 7004));
        jedisClusterNodes.add(new HostAndPort("192.168.80.4", 7005));
        jedisClusterNodes.add(new HostAndPort("192.168.80.4", 7006));
        jedisClusterNodes.add(new HostAndPort("192.168.80.4", 7007));
        jedisClusterNodes.add(new HostAndPort("192.168.80.4", 7008));

        JedisCluster jc = new JedisCluster(jedisClusterNodes);
        System.out.println("连接redisCluster成功");
        jc.set("lagou", "www.lagou.com");
        System.out.println("设置key:lagou");
        String value = jc.get("lagou");
        System.out.println("lagou 的值为" + value);
    }
}
